<?php use_javascript('jquery-1.3.2.min.js') ?>
<?php use_helper ('Form','Javascript','Object', 'DateForm') ?>

<?php if (!$flag):?>
<?php echo form_tag('Billing/listPaidBill') ?>
<table class="form" width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr height="30">
  	<td colspan="4" valign="top"> <h3>Please Select Station and Month to view bills.</h3>
  </tr>
 
  <tr height="30">
		<td width="14%"><strong>Station:</strong></td>
		<td width="86%"> <?php echo object_select_tag('', '', array ( 'name'=>'station_id', 'id'=>'station_id', 'related_class' => 'Station' , 'peer_method' => 'GetStation'));?></td>
  </tr>


  <tr style="height:30px;">
    <td width="15%"><strong>Billing Month/Year:</strong></td>
    <td width="85%"><?php echo select_month_tag('billing_month', date('m')-1, 'use_short_month=true'); ?><?php echo select_year_tag('billing_year', date('Y'), 'year_end=2020') ?>
    </td>
</tr>

	
	<tr height="50">
		<td>&nbsp;</td>
		<td colspan="2" valign="top">
		<table width="100%" align="left" border="0" class="form">
			<tr>
				<td width="2%"><?php echo submit_tag(' ', array('class' => 'btn_submit', 'style'=>'border:none')); ?> </td>
				<td width="96%">&nbsp;</td>
			</tr>
    	</table>
		</td>
  </tr>
  
  </table>
  </form>
<?php endif ;?>


<?php if($flag):?>
<?php echo form_tag('Billing/revertElecBillPayment');?>

<script language="javascript">

	function checkBoxes(type){
	  	if(type == "selectall"){
		   var checked_status = this.checked;
		   jQuery("input[name*='selected']").each(function(){
		   	this.checked = true;
			   });
	  		 }
	   else{
		   var checked_status = this.checked;
		   jQuery("input[name*='selected']").each(function()
		   {
			this.checked = false;
			});
	  	 }
	  }
</script>


<?php if (count($bills)): ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0"  class="heading_table">
    <tr>
        <td height="30"><span class="heading">Utility Bills of <?php echo $station;?> the Month: <?php echo $bill_month;?> </span></td>
        <td align="right" height="30" valign="bottom"><strong><font color="#000000">Select:</font> </strong><?php echo link_to_function('All', 'checkBoxes("selectall")')?> , <?php echo link_to_function('None', 'checkBoxes("unselectall")')?>
        </td>
    </tr>
    
</table> 
 

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="datagrid">
    <tr>
        <th width="29%" style="text-align:left;">Rank/Name</th>
        <th width="14%" style="text-align:left;">Consumer No.</th>
        <th width="9%" style="text-align:left;">Previous</th>
        <th width="9%" style="text-align:left;">Present</th>
        <th width="9%" style="text-align:left;">Units</th>
		<th width="11%" style="text-align:left;">Total Bill</th>
        <th width="9%" style="text-align:left;">Payment</th>
        <th width="10%" style="text-align:left;">Operation</th>
    </tr>

<?php foreach ($bills as $j => $bill) : ?>
    <tr>
        <td align="left"><?php echo link_to($bill->getOccupant()->getRank().' '.$bill->getOccupant()->getName(), 'Billing/detailBill?id='.Utility::EncryptQueryString($bill->getId())); ?> </td>
        <td align="left"><?php echo $bill->getConsumerNo(); ?></td>
        <td align="left"><?php echo $bill->getPreviousReading(); ?></td>
        <td align="left"><?php echo $bill->getPresentReading(); ?></td>
        <td align="left"><?php echo $bill->getUnitsConsumed(); ?></td>
		<td align="left">Rs. <?php echo $bill->getGrandTotal(); ?></td>
        <td align="left"><?php if ($bill->getPaymentStatus() == Constant::BILL_PAID) echo checkbox_tag('selected['. $j.']', $bill->getId(), false); else echo '<strong>'.Constant::BILL_UNPAID_TITLE.'</strong>'?></td>
        <td align="right" class="edit">
        <?php //echo link_to('&nbsp;','Building/edit?id='.Utility::EncryptQueryString($bill->getId()),array('title'=>'Edit', 'class' => 'edit'))?>
        <?php echo link_to('&nbsp;','Billing/deleteElecBill?id='.Utility::EncryptQueryString($bill->getId()), array('confirm'=>'A deleted bill will not be recoverable. Are you sure you want to Delete this bill?', 'title'=>'Delete', 'class' => 'delete')); ?>
        </td>
    </tr>

<?php endforeach; ?>
    <tr>
   		<td class="last">&nbsp;</td>
    </tr>
    
    <tr>
	<td colspan="8">
	<table width="100%"  align="left" border="0">
      <tr>
        <td width="80%">&nbsp;</td>
        <td width="20%"><?php echo submit_tag('', array('class'=>'btn_unpaid', 'style'=>'border:none')); ?></td>
      </tr>
    </table>
	</td>
  </tr>
</table>
	<?php else:?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="datagrid">
    <tr>
        <th width="27%" style="text-align:left;">Rank/Name</th>
        <th width="14%" style="text-align:left;">Consumer No.</th>
        <th width="11%" style="text-align:left;">Previous</th>
        <th width="11%" style="text-align:left;">Present</th>
        <th width="12%" style="text-align:left;">Billed Units</th>
		<th width="15%" style="text-align:left;">Total Bill</th>
        <th width="10%" style="text-align:left;">Operation</th>
    </tr>
    <tr>
        <td colspan="7" style="background:none; text-align:center;"><?php echo "No Record Found." ?></td>
    </tr>
    </table>
    <?php endif; ?>
</form> 
<?php endif ; //IF OF FLAG TO DISPLAY PAGE IN PARTS?>